/*
 * protos.h
 *
 *  Created on: Mar 27, 2013
 *      Author: locpm
 */

#ifndef PROTOS_H_
#define PROTOS_H_

#include "defines.h"

BOOL doCommand(const char* buf);
void readCommands();
void displayBitBoard(BITBOARD bitboard);

/* setting all bits to 0 */
void clearBitBoard(BITBOARD* bitboard);

/* Logical operations like taking the AND of two bitboards */
BITBOARD andTwoBitBoards(BITBOARD bitboard1, BITBOARD bitboard2);

/* Logical operations like taking the OR of two bitboards */
BITBOARD orTwoBitBoards(BITBOARD bitboard1, BITBOARD bitboard2);

/* Logical operations like taking the XOR of two bitboards */
BITBOARD xorTwoBitBoards(BITBOARD bitboard1, BITBOARD bitboard2);

/* Logical operations like taking the AND of numBB bitboards */
BITBOARD andMultipleBitBoards(BITBOARD bitboard[], int numBB);

/* Logical operations like taking the OR of numBB bitboards */
BITBOARD orMultipleBitBoards(BITBOARD[], int numBB);

/* Logical operations like taking the XOR of numBB bitboards */
BITBOARD xorMultipleBitBoards(BITBOARD bitboard[], int numBB);

/* Logical operations like taking the NOT of a bitboard */
BITBOARD notBitBoard(BITBOARD bitboard);

/* Check if bitboard has only zero bits */
int isAllZeroBit(BITBOARD bitboard);

/*
 * Find the least significant index or position of the bits set to one in the U32 word
 * Note: this algorithm does not handle the zero input
 * See http://en.wikipedia.org/wiki/Find_first_set
 *
 * Don't use this if u32 = 0
 */
U32 findFirstOne(U32 u32);

/*
 * Find the most significant index or position of the bits set to one in the U32 word
 * Note: this algorithm does not handle the zero input
 * See http://en.wikipedia.org/wiki/Most_significant_bit
 *
 * Don't use this if u32 = 0
 */
U32 findLastOne(U32 u32);

/**
 * Don't use this if bitboard = 0
 */
U32 findFirstOneInBitBoard(BITBOARD bitboard);

/**
 * Don't use this if bitboard = 0
 */
U32 findLastOneInBitBoard(BITBOARD bitboard);

void displayMove(MOVE move);
unsigned int movegen(unsigned int index);

// makeMove function used for "move <moveText>" command
void makeMove(MOVE move);

// unMakeMove function used for "undo" command
void unMakeMove(MOVE move);

BOOL isValidTextMove(char *userMove, MOVE *move);

BOOL isOtherKingAttacked();

BOOL isAttacked(BITBOARD targetBitBoard, unsigned char fromSide);

void makeCapture(unsigned int captured, unsigned int to);
void unMakeCapture(unsigned int captured, unsigned int to);

BOOL isTwoKingsFaceToFace();

unsigned int bitCnt(U32 u32);
unsigned int bitCntBB(BITBOARD bitboard);

void displaySearchStats(int mode, int depth, int score);

U64 perft(int fly, int depth);

#endif /* PROTOS_H_ */
